#pragma once

#include "fxcc/core/graph/opengl3/Shader.h"
#include "fxcc/core/graph/opengl3/MeshJack.h"
#include "fxcc/core/graph/opengl3/font/FontLib.h"
#include "fxcc/core/graph/opengl3/EffectBase.h"

namespace fxcc
{
    namespace graph
    {
        namespace opengl3
        {
            namespace font
            {
                struct FXCC_API  Factory
                {
                    std::unordered_map<std::string, std::shared_ptr<FontLib>> m_FontLibs;

                    bool RegisterFontFile(const std::string& path)
                    {
                        if (HasFontFamily(path))
                        {
                            return true;
                        }

                        std::shared_ptr<fxcc::graph::opengl3::font::FontLib> fontLib = std::make_shared<fxcc::graph::opengl3::font::FontLib>(path);

                        if (fontLib->m_Available)
                        {
                            m_FontLibs[path] = fontLib;
                        }
                        return fontLib->m_Available;
                    }

                    bool HasFontFamily(const std::string &fontFamily)
                    {
                        return m_FontLibs.find(fontFamily) != m_FontLibs.end();
                    }

                    std::vector<std::string> GetFamilys()
                    {
                        std::vector<std::string> res;
                        for (const auto &it : m_FontLibs)
                        {
                            res.push_back(it.first);
                        }
                        return res;
                    };
                    std::shared_ptr<fxcc::graph::opengl3::font::FontLib> GetFontFamily(const std::string &key)
                    {
                        auto it = m_FontLibs.find(key);
                        if (it != m_FontLibs.end())
                        {
                            return m_FontLibs[key];
                        }

                        return 0;
                    }
                    std::shared_ptr<FontLib> GetFontLib(const std::string& path);
                    static Factory& Inst()
                    {
                        static Factory res;
                        return res;
                    }
                };
            };
        }
    };
}